package com.zhoumy.interview.study.thread;

/**
 * SingleThreadSingletonDemo（单线程的 单例模式）
 *
 * @author: zhoumy
 * @create: 2024年6月3日16:39:51
 */
public class SingleThreadSingletonDemo {

    private static SingleThreadSingletonDemo instance = null;

    private SingleThreadSingletonDemo() {
        System.out.println(Thread.currentThread().getName() + "\t 我是构造方法SingletonDemo");
    }

    public static SingleThreadSingletonDemo getInstance() {
        if(instance == null) {
            instance = new SingleThreadSingletonDemo();
        }
        return instance;
    }

    public static void main(String[] args) {
        // 这里的 == 是比较内存地址
        System.out.println(SingleThreadSingletonDemo.getInstance() == SingleThreadSingletonDemo.getInstance());
        System.out.println(SingleThreadSingletonDemo.getInstance() == SingleThreadSingletonDemo.getInstance());
        System.out.println(SingleThreadSingletonDemo.getInstance() == SingleThreadSingletonDemo.getInstance());
        System.out.println(SingleThreadSingletonDemo.getInstance() == SingleThreadSingletonDemo.getInstance());
    }
}